package com.sponsorpay.sdk.android.utils;

import android.net.Uri;
import android.net.Uri.Builder;
import com.sponsorpay.sdk.android.SponsorPay;
import com.sponsorpay.sdk.android.credentials.SPCredentials;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

public class UrlBuilder
{
  private static final String ANDROID_ID_KEY = "android_id";
  private static final String APPID_KEY = "appid";
  private static final String APP_BUNDLE_NAME_KEY = "app_bundle_name";
  private static final String APP_VERSION_KEY = "app_version";
  private static final String CARRIER_COUNTRY_KEY = "carrier_country";
  private static final String CARRIER_NAME_KEY = "carrier_name";
  private static final String CURRENCY_KEY = "currency";
  private static final String LANGUAGE_KEY = "language";
  private static final String MANUFACTURER_KEY = "manufacturer";
  private static final String NETWORK_CONNECTION_TYPE_KEY = "network_connection_type";
  private static final String OS_VERSION_KEY = "os_version";
  private static final String PHONE_VERSION_KEY = "phone_version";
  private static final String SCREEN_DENSITY_CATEGORY_KEY = "screen_density_category";
  private static final String SCREEN_DENSITY_X_KEY = "screen_density_x";
  private static final String SCREEN_DENSITY_Y_KEY = "screen_density_y";
  private static final String SCREEN_HEIGHT_KEY = "screen_height";
  private static final String SCREEN_WIDTH_KEY = "screen_width";
  private static final String SDK_RELEASE_VERSION_KEY = "sdk_version";
  private static final String UDID_KEY = "device_id";
  public static final String URL_PARAM_ALLOW_CAMPAIGN_KEY = "allow_campaign";
  public static final String URL_PARAM_CURRENCY_NAME_KEY = "currency";
  public static final String URL_PARAM_OFFSET_KEY = "offset";
  private static final String URL_PARAM_SIGNATURE = "signature";
  public static final String URL_PARAM_VALUE_ON = "on";
  private static final String USERID_KEY = "uid";
  private static final String WIFI_MAC_ADDRESS_KEY = "mac_address";
  private SPCredentials mCredentials;
  private String mCurrency;
  private Map<String, String> mExtraKeysValues;
  private String mResourceUrl;
  private boolean mShouldAddScreenMetrics;
  private boolean mShouldAddUserId = true;

  protected UrlBuilder(String paramString, SPCredentials paramSPCredentials)
  {
    this.mResourceUrl = paramString;
    this.mCredentials = paramSPCredentials;
  }

  public static Map<String, String> mapKeysToValues(String[] paramArrayOfString1, String[] paramArrayOfString2)
  {
    if (paramArrayOfString1.length != paramArrayOfString2.length)
      throw new IllegalArgumentException("SponsorPay SDK: When specifying Custom Parameters using two arrays of Keys and Values, both must have the same length.");
    HashMap localHashMap = new HashMap(paramArrayOfString1.length);
    for (int i = 0; ; i++)
    {
      if (i >= paramArrayOfString1.length)
        return localHashMap;
      String str1 = paramArrayOfString1[i];
      String str2 = paramArrayOfString2[i];
      if ((StringUtils.nullOrEmpty(str1)) || (StringUtils.nullOrEmpty(str2)))
        throw new IllegalArgumentException("SponsorPay SDK: When specifying Custom Parameters using two arrays of Keys and Values, none of their elements can be empty or null.");
      localHashMap.put(str1, str2);
    }
  }

  public static UrlBuilder newBuilder(String paramString, SPCredentials paramSPCredentials)
  {
    return new UrlBuilder(paramString, paramSPCredentials);
  }

  public static void validateKeyValueParams(Map<String, String> paramMap)
  {
    Iterator localIterator;
    if (paramMap != null)
      localIterator = paramMap.entrySet().iterator();
    Map.Entry localEntry;
    do
    {
      if (!localIterator.hasNext())
        return;
      localEntry = (Map.Entry)localIterator.next();
    }
    while ((!StringUtils.nullOrEmpty((String)localEntry.getKey())) && (!StringUtils.nullOrEmpty((String)localEntry.getValue())));
    throw new IllegalArgumentException("SponsorPay SDK: Custom Parameters cannot have an empty or null Key or Value.");
  }

  public UrlBuilder addExtraKeysValues(Map<String, String> paramMap)
  {
    if (paramMap != null)
    {
      if (this.mExtraKeysValues == null)
        this.mExtraKeysValues = new HashMap(paramMap);
    }
    else
      return this;
    this.mExtraKeysValues.putAll(paramMap);
    return this;
  }

  public UrlBuilder addScreenMetrics()
  {
    this.mShouldAddScreenMetrics = true;
    return this;
  }

  public String buildUrl()
  {
    HashMap localHashMap = new HashMap();
    if (this.mShouldAddUserId)
      localHashMap.put("uid", this.mCredentials.getUserId());
    HostInfo localHostInfo = this.mCredentials.getHostInfo();
    localHashMap.put("sdk_version", SponsorPay.RELEASE_VERSION_STRING);
    localHashMap.put("appid", this.mCredentials.getAppId());
    localHashMap.put("device_id", localHostInfo.getUDID());
    localHashMap.put("os_version", localHostInfo.getOsVersion());
    localHashMap.put("phone_version", localHostInfo.getPhoneVersion());
    localHashMap.put("language", localHostInfo.getLanguageSetting());
    localHashMap.put("android_id", localHostInfo.getAndroidId());
    localHashMap.put("mac_address", localHostInfo.getWifiMacAddress());
    localHashMap.put("carrier_name", localHostInfo.getCarrierName());
    localHashMap.put("carrier_country", localHostInfo.getCarrierCountry());
    localHashMap.put("network_connection_type", localHostInfo.getConnectionType());
    localHashMap.put("manufacturer", localHostInfo.getManufacturer());
    localHashMap.put("app_bundle_name", localHostInfo.getAppBundleName());
    localHashMap.put("app_version", localHostInfo.getAppVersion());
    if (StringUtils.notNullNorEmpty(this.mCurrency))
      localHashMap.put("currency", this.mCurrency);
    if (this.mShouldAddScreenMetrics)
    {
      localHashMap.put("screen_width", localHostInfo.getScreenWidth());
      localHashMap.put("screen_height", localHostInfo.getScreenHeight());
      localHashMap.put("screen_density_x", localHostInfo.getScreenDensityX());
      localHashMap.put("screen_density_y", localHostInfo.getScreenDensityY());
      localHashMap.put("screen_density_category", localHostInfo.getScreenDensityCategory());
    }
    if (this.mExtraKeysValues != null)
    {
      validateKeyValueParams(this.mExtraKeysValues);
      localHashMap.putAll(this.mExtraKeysValues);
    }
    Map localMap = SponsorPayParametersProvider.getParameters();
    if (!localMap.isEmpty())
      localHashMap.putAll(localMap);
    Uri.Builder localBuilder = Uri.parse(this.mResourceUrl).buildUpon();
    Iterator localIterator = localHashMap.entrySet().iterator();
    while (true)
    {
      if (!localIterator.hasNext())
      {
        String str = this.mCredentials.getSecurityToken();
        if (StringUtils.notNullNorEmpty(str))
          localBuilder.appendQueryParameter("signature", SignatureTools.generateSignatureForParameters(localHashMap, str));
        return localBuilder.build().toString();
      }
      Map.Entry localEntry = (Map.Entry)localIterator.next();
      localBuilder.appendQueryParameter((String)localEntry.getKey(), (String)localEntry.getValue());
    }
  }

  public UrlBuilder sendUserId(boolean paramBoolean)
  {
    this.mShouldAddUserId = paramBoolean;
    return this;
  }

  public UrlBuilder setCurrency(String paramString)
  {
    this.mCurrency = paramString;
    return this;
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.sponsorpay.sdk.android.utils.UrlBuilder
 * JD-Core Version:    0.6.2
 */